$(function () {
    $.menuSelector('#dishes_dish');

    Ifonly.Uploader2.single('#dish-cover-ctx', {
        input: {
            name: 'dish.cover',
            class: 'validate[required]'
        },
        fileVal: 'dish.cover',
        uploadType: Ifonly.Uploader2.UploadType.image,
        formData: {
            attachmentType: 'dish_cover'
        },
        callbacks: {
            remove: function(fileId, dataId) {
                var id = $('#dishId').val();
                if (id && dataId) {
                    Ifonly.Service.get(Ifonly.ctx + '/dishes/dish/cover', {id:id}, function() {
                        Ifonly.Notification.alert('删除封面成功')
                    }, function() {
                        Ifonly.Notification.alert('删除封面失败')
                    });
                }
            }
        }
    });

    Ifonly.Uploader2.multiple('#dish-pictures-ctx', {
        input: {
            name: 'dish.pictures',
            class: 'validate[required]'
        },
        fileVal: 'dish.pictures',
        uploadType: Ifonly.Uploader2.UploadType.image,
        formData: {
            attachmentType: 'dish_cover'
        }
    });

    var ue = Ifonly.UEditor.init('container', {
        toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', 'pagebreak', 'template', 'background', '|',
            'horizontal', 'date', 'time', 'spechars'
        ]],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });

    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });

    Ifonly.Validator.attach('#data-form');

});